package com.yand.thinkingInJava.thinkingInJava21.threadcooperation;


import java.util.concurrent.BlockingQueue;

class LiftOff{}


class LiftOffRunner implements Runnable{
    private BlockingQueue<LiftOff> rockets;

    public LiftOffRunner(BlockingQueue<LiftOff> queue){
        rockets = queue;
    }

    public void add(LiftOff lo){
        try{
            rockets.put(lo);
        }catch (InterruptedException e){
            System.out.println("InterruptedException during put()");
        }
    }


    @Override
    public void run() {
        try{

            while(!Thread.interrupted()){
                LiftOff rocket = rockets.take();
                //rocket.run();
            }
        }catch (InterruptedException e){
            System.out.println("Waking form take()");
        }
        System.out.println("Exiting LIftOffRunner");

    }
}


/**
 * 同步队列解决生产者-消费者这个经典的问题
 * demo 中 LiftOff 类缺失， 改由下面的实例
 *
 * ToastOMatic.java 实现
 *
 */
public class TestBlockingQueues {
}
